<template>
  <el-dialog
    class="addedit-contract-dialog"
    width="1200px"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    v-dialogDrag="true"
    @open="handleDialogOpen"
    @closed="handleDialogClosed"
  >
    <template slot="title">
      <span class="el-dialog__title" v-if="operType == 'add'">新增收入合同</span>
      <span class="el-dialog__title" v-if="operType == 'edit'">修改收入合同</span>
      <span class="el-dialog__title" v-if="operType == 'update'">变更收入合同</span>
      <span class="el-dialog__title" v-if="operType == 'detail'">查看收入合同</span>
    </template>
    <el-form
      ref="addEditContractForm"
      :model="formData"
      :rules="formRules"
      size="small"
      label-width="100px"
      :disabled="operType == 'detail'"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="客户:" prop="entrustOrganizationId">
            <OrganizationSelect
              style="width: 100%;"
              ref="clientOrganizationSelect"
              v-model="formData.entrustOrganizationId"
            ></OrganizationSelect>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="代理商:" prop="agent">
            <el-input v-model="formData.agent" placeholder="请输入" :clearable="false">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="编号:" prop="agreementNumber">
            <el-input v-model="formData.agreementNumber" placeholder="请输入" :clearable="false">
              <!-- <div
                slot="suffix"
                style="color: #409EFF; cursor: pointer; padding: 0 5px;"
                @click="handleGenerateNumber"
                v-if="operType != 'detail'"
              >自动生成</div> -->
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="签订日期:" prop="signDate">
            <el-date-picker
              style="width: 100%;"
              v-model="formData.signDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="请选择"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="业务员:" prop="businessUser">
            <el-select
              style="width: 100%;"
              v-model="formData.businessUser"
              clearable
              filterable
            >
              <el-option
                v-for="(item, index) in userList"
                :key="index"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门:" prop="deptId">
            <el-select
              style="width: 100%;"
              v-model="formData.deptId"
              clearable
              filterable
            >
              <el-option
                v-for="(item, index) in saleDeptList"
                :key="index"
                :label="item.deptName"
                :value="item.deptId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="项目:" :prop="!isAddItem ? 'itemId' : 'itemName'">
            <div style="display: flex;">
              <!-- <el-select
                v-if="!isAddItem"
                popper-class="project-select-popper"
                style="width: 100%;"
                v-model="formData.itemId"
                clearable
                filterable
                @change="(value) => {
                  if (!value) formData.itemDate = []
                  else {
                    const findRes = projectList.find(item => item.agreementItemId == value)
                    formData.itemDate = [findRes.beginTime, findRes.endTime]
                    formData.itemName = findRes ? findRes.itemName : ''
                  }
                }"
              >
                <el-option
                  v-for="(item, index) in projectList"
                  :key="index"
                  :title="item.itemName"
                  :label="item.itemName"
                  :value="item.agreementItemId"
                ></el-option>
              </el-select> -->
              <ProjectSelect
                style="width: 100%;"
                popper-class="project-select-popper"
                ref="projectSelect"
                v-model="formData.itemId"
                @change="(value, option) => {
                  if (!value) formData.itemDate = []
                  else {
                    formData.itemDate = [option.beginTime, option.endTime]
                    formData.itemName = option ? option.itemName : ''
                  }
                }"
                v-if="!isAddItem"
              ></ProjectSelect>
              <el-input v-else style="width: 100%;" v-model="formData.itemName" placeholder="请输入项目名称"></el-input>
              <el-button style="margin-left: 4px;" icon="el-icon-plus" size="mini" plain type="primary" @click="handleAddItem">{{ !isAddItem ? '新增项目' : '选择项目'}}</el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="期限:" prop="itemDate">
            <el-date-picker
              style="width: 100%;"
              v-model="formData.itemDate"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :unlink-panels="true"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="类型:" prop="agreementType">
            <el-select
              style="width: 100%;"
              v-model="formData.agreementType"
              clearable
              filterable
              multiple
            >
              <el-option
                v-for="(item, index) in dict.type.agreement_type"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="交付地址:" prop="deliveryAddress">
            <el-input
              v-model="formData.deliveryAddress"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="交付日期:" prop="deliveryDate">
            <el-date-picker
              style="width: 100%;"
              v-model="formData.deliveryDate"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="请选择"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="" prop="" label-width="25px">
            <div style="margin-bottom: 10px;">
              <label style="margin-right: 20px;">产品/服务:</label>
              <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddProductRow">添加明细</el-button>
            </div>
            <el-table
              style="width: 100%"
              :data="formData.products"
            >
              <el-table-column type="index" label="序号" align="center" width="50">
              </el-table-column>
              <el-table-column label="产品" prop="productId" align="center" min-width="200">
                <template slot="header">
                  <span style="color: red;">*</span>
                  <span>产品/服务</span>
                </template>
                <template slot-scope="scope">
                  <div style="display: flex;">
                    <el-select
                      style="flex: 1;"
                      v-model="scope.row.productId"
                      :clearable="true"
                      :filterable="true"
                    >
                      <el-option
                        v-for="(item, index) in productList"
                        :key="index"
                        :label="item.productName"
                        :value="item.productId"
                      >
                        <span>{{ item.productCode }}：{{ item.productName }}</span>
                      </el-option>
                    </el-select>
                     <el-button style="margin-left: 4px;" plain icon="el-icon-plus" size="mini" v-hasPermi="['basic:productServer:add']" @click="handleAddProduct"></el-button>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="数量" align="center" prop="quantity" min-width="80">
                <template slot="header">
                  <span style="color: red;">*</span>
                  <span>数量</span>
                </template>
                <template slot-scope="scope">
                  <el-input-number
                    style="width: 100%;"
                    v-model="scope.row.quantity"
                    placeholder="请输入"
                    :min="0"
                    :precision="0"
                    :controls="false"
                    @blur="calculateRowAmount(scope.row, 'quantity')"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="销售单价" align="center" prop="salesUnitPrice" min-width="80">
                <template slot="header">
                  <span style="color: red;">*</span>
                  <span>销售单价</span>
                </template>
                <template slot-scope="scope">
                  <el-input-number
                    style="width: 100%;"
                    v-model="scope.row.salesUnitPrice"
                    placeholder="请输入"
                    :min="0"
                    :precision="2"
                    :controls="false"
                    @blur="calculateRowAmount(scope.row, 'salesUnitPrice')"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="金额" align="center" prop="amount" min-width="80">
                <template slot="header">
                  <span style="color: red;">*</span>
                  <span>金额</span>
                </template>
                <template slot-scope="scope">
                  <el-input-number
                    style="width: 100%;"
                    v-model="scope.row.amount"
                    placeholder="请输入"
                    :min="0"
                    :precision="2"
                    :controls="false"
                    @blur="calculateRowAmount(scope.row, 'amount')"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="备注" align="center" prop="remark" min-width="120">
                <template slot-scope="scope">
                  <el-input
                    style="width: 100%;"
                    v-model="scope.row.remark"
                    placeholder="请输入"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" prop="" width="60" key="oper">
                <template slot-scope="scope">
                  <el-link type="danger" @click="handleRemoveProduct(scope.$index)">删除</el-link>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="金额:" prop="signAmount">
            <el-input-number
              style="width: 100%;"
              v-model="formData.signAmount"
              placeholder="请输入"
              :min="0"
              :precision="2"
              :controls="false"
              @blur="calculateActualAmount"
            ></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="税率:" prop="taxRate">
            <el-input-number
              style="width: 100%;"
              v-model="formData.taxRate"
              placeholder="请输入"
              :min="0"
              :precision="2"
              :controls="false"
              @blur="calculateActualAmount"
            ></el-input-number>
            <span class="append">%</span>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label=" " prop="includeTax" label-width="10px">
            <el-radio-group v-model="formData.includeTax" @change="calculateActualAmount">
              <el-radio :label="1">含税</el-radio>
              <el-radio :label="0">不含税</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="金额合计:" prop="actualAmount">
            <el-input-number
              style="width: 100%;"
              v-model="formData.actualAmount"
              placeholder="请输入"
              :min="0"
              :precision="2"
              :controls="false"
              :disabled="true"
            ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-divider></el-divider>

      <el-row>
        <el-col :span="12">
          <el-form-item label="收款账号:" prop="receivingAccount">
            <el-input
              v-model="formData.receivingAccount"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="约定开票金额:" prop="agreedInvoiceAmount" label-width="120px">
            <el-input-number
              style="width: 100%;"
              v-model="formData.agreedInvoiceAmount"
              placeholder="请输入"
              :min="0"
              :precision="2"
              :controls="false"
            ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="纸质合同是否签订:" prop="signStatus" label-width="130px">
            <el-radio-group v-model="formData.signStatus">
              <el-radio
                v-for="(item, index) in dict.type.is_or_no"
                :key="index"
                :label="Number(item.value)"
              >{{ item.label }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="备注:" prop="remark">
            <el-input
              type="textarea"
              rows="3"
              maxlength="100"
              show-word-limit
              v-model="formData.remark"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="附言:" prop="postscript">
            <el-input
              type="textarea"
              rows="3"
              maxlength="100"
              show-word-limit
              v-model="formData.postscript"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="欠款催收进度:" prop="collectionProgress">
            <el-input
              type="textarea"
              rows="3"
              maxlength="100"
              show-word-limit
              v-model="formData.collectionProgress"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="附件:" prop="agreementFileOssId">
            <el-upload
              ref="attachmentUploadRef"
              :action="uploadParams.url"
              :headers="uploadParams.headers"
              :before-upload="handleBeforeUpload"
              :on-success="handleSuccessFile"
              :on-error="handleErrorFile"
              :on-remove="handleRemoveFile"
              :on-preview="handlePreviewFile"
              :file-list="attachmentFileList"
              multiple
            >
              <el-button icon="el-icon-upload" size="mini" plain type="primary">添加附件</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div class="dialog-footer" slot="footer">
      <template v-if="operType != 'detail'">
        <!-- 新增/修改操作 才有暂存 -->
        <el-button style="margin-right: 50px;" type="primary" @click="handleSave(false)" v-if="operType == 'add' || operType == 'edit'">暂存</el-button>
        <el-button style="margin-right: 50px;" type="primary" @click="handleSave(true)">提交</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </template>
      <template v-if="operType == 'detail'">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </template>
    </div>

    <AddEditProductDialog
      :show.sync="showAddEditProductDialog"
      operType="add"
      @refresh="getAllProductList"
    ></AddEditProductDialog>
  </el-dialog>
</template>

<script>
import AddEditProductDialog from './AddEditProductDialog.vue'
import { userListingIgnorePermission } from '@/api/system/user'
import { listDeptIgnorePermission } from '@/api/system/dept'
// import { projectListAll } from '@/api/person/project'
import { productListAll } from '@/api/person/product'
import {
  contractDetail,
  contractAdd,
  contractEdit,
  contractUpdate,
  genContractNumber
} from '@/api/person/contract'
import { getToken } from '@/utils/auth'

export default {
  name: 'AddEditContractDialog',
  components: {
    AddEditProductDialog,
  },
  dicts: ['agreement_type', 'is_or_no'],
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    operType: {
      type: String,
      default: 'add',
    },
    row: {
      type: Object,
      default: () => ({})
    },
  },
  computed: {
    dialogVisible: {
      get() {
        return this.show
      },
      set(value) {
        this.$emit('update:show', value)
      }
    }
  },
  data() {
    return {
      userList: [],
      saleDeptList: [],
      // projectList: [],
      productList: [],
      formData: {},
      formRules: {
        entrustOrganizationId: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        agent: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        agreementNumber: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        signDate: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        businessUser: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        deptId: [],
        itemId: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        itemName: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        itemDate: [
          { required: false, message: '请选择', trigger: 'change' }
        ],
        agreementType: [],
        deliveryAddress: [],
        deliveryDate: [],
        products: [],
        signAmount: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        taxRate: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        includeTax: [],
        actualAmount: [
          { required: true, message: '请输入', trigger: 'blur' }
        ],
        receivingAccount: [],
        agreedInvoiceAmount: [],
        signStatus: [],
        remark: [],
        postscript: [],
        collectionProgress: [],
        agreementFileOssId: [],
      },
      // 文件上传参数
      uploadParams: {
        url: process.env.VUE_APP_BASE_API + '/system/oss/upload',
        headers: {
          Authorization: 'Bearer ' + getToken(),
          'Content-Disposition': 'inline',

        },
      },
      attachmentFileList: [],
      isAddItem: false,

      showAddEditProductDialog: false,
    }
  },
  created() {
    this.initFormData()
  },
  methods: {
    // 弹框打开时
    handleDialogOpen() {
      this.getAllProductList()

      if (this.operType == 'edit' || this.operType == 'update' || this.operType == 'detail') {
        contractDetail(this.row.agreementId).then(res => {
          for (let key in this.formData) {
            this.formData[key] = res.data[key]
          }
          this.formData.agreementType = res.data.agreementType?.split(',') || []
          this.formData.itemDate = [res.data.beginTime, res.data.endTime]
          this.attachmentFileList = JSON.parse(res.data.agreementFileOssId || '[]')
          this.formData.products?.forEach(row => {
            const findRes = this.productList.find(item => item.productId == row.productId)
            if (!findRes) {
              this.productList.unshift({
                customFlag: true,
                productId: row.productId,
                productName: row.productName + '（弃用）',
                productCode: row.productCode,
              })
            }
          })
        }).catch(err => {})
        this.$nextTick(() => {
          this.$refs['clientOrganizationSelect'].setDefaultOption({
            entrustOrganizationId: this.row.entrustOrganizationId,
            organizationName: this.row.organizationName
          })
          this.$refs['projectSelect'].setDefaultOption({
            agreementItemId: this.row.itemId,
            itemName: this.row.itemName
          })
        })
      }

      if (this.userList.length <= 0) {
        userListingIgnorePermission().then(res => {
          this.userList = res.data || []
        }).catch(err => {})
      }

      if (this.saleDeptList.length <= 0) {
        listDeptIgnorePermission({parentId: 0 }).then(res => {
          this.saleDeptList = res.data || []
        }).catch(err => {})
      }

      // projectListAll().then(res => {
      //   this.projectList = res.data || []
      // }).catch(err => {})
    },
    // 弹框关闭时
    handleDialogClosed() {
      this.productList = []
      this.initFormData()
      this.$refs.addEditContractForm.resetFields()
      this.attachmentFileList = []
      this.$refs['clientOrganizationSelect'].init()
      this.$refs['projectSelect'].init()
    },
    // 初始化表单数据
    initFormData() {
      this.formData = {
        entrustOrganizationId: '',
        agent: '',
        agreementNumber: '',
        signDate: '',
        businessUser: '',
        deptId: '',
        itemId: '',
        itemDate: [],
        agreementType: [],
        deliveryAddress: '',
        deliveryDate: '',
        products: [],
        signAmount: undefined,
        taxRate: undefined,
        includeTax: 1,
        actualAmount: undefined,
        receivingAccount: '',
        agreedInvoiceAmount: undefined,
        signStatus: 0,
        remark: '',
        postscript: '',
        collectionProgress: '',
        agreementFileOssId: '',
        itemName: ''
      }
      this.isAddItem = false
    },
    // 获取表单数据
    getFormData() {
      const data = JSON.parse(JSON.stringify(this.formData))
      data.agreementType = data.agreementType?.join(',') || ''
      data.beginTime = data.itemDate ? data.itemDate[0] : ''
      data.endTime = data.itemDate ? data.itemDate[1] : ''
      delete data.itemDate
      data.agreementFileOssId = JSON.stringify(this.attachmentFileList?.map(item => ({
        ossId: item.response?.data.ossId || item.ossId,
        url: item.response?.data.url || item.url,
        name: item.response?.data.name || item.name
      })) || [])
      if (this.operType == 'edit' || this.operType == 'update') {
        data.agreementId = this.row.agreementId
      }
      return data
    },
    // 获取全部产品列表
    getAllProductList() {
      productListAll().then(res => {
        const resultList = []
        const customList = this.productList.filter(item => item.customFlag)
        resultList.push(...customList)
        const rows = res.data || []
        rows.forEach(row => {
          const findRes = customList.find(item => item.productId == row.productId)
          if (!findRes) resultList.push(row)
        })
        this.productList = resultList
        // this.productList.push(...res.data || [])
      }).catch(err => {})
    },
    // 自动生成编号
    handleGenerateNumber() {
      genContractNumber().then(res => {
        this.formData.agreementNumber = res.data || ''
      }).catch(err => {})
    },
    isBlank(value) {
      return value === null || value === undefined || value === ''
    },
    // 计算总金额
    calculateRowAmount(row, field) {
      if (row) {
        if (field == 'quantity' && !this.isBlank(row.quantity)) {
          if (!this.isBlank(row.salesUnitPrice)) {
            row.amount = row.quantity * row.salesUnitPrice
          }
        }

        if (field == 'salesUnitPrice' && !this.isBlank(row.salesUnitPrice)) {
          if (!this.isBlank(row.quantity)) {
            row.amount = row.quantity * row.salesUnitPrice
          }
        }

        if (field == 'amount' && !this.isBlank(row.amount)) {
          if (!this.isBlank(row.quantity) && row.quantity !== 0) {
            row.salesUnitPrice = row.amount / row.quantity
          }
        }
      }

      this.formData.signAmount = this.formData.products.reduce((pre, cur) => {
        let result = pre + (cur.amount || 0)
        return result
      }, 0)
      this.calculateActualAmount()
    },
    // 计算实际金额
    calculateActualAmount() {
      if (this.formData.includeTax == 1) { // 含税
        if (!this.isBlank(this.formData.signAmount)) {
          this.formData.actualAmount = this.formData.signAmount
        } else {
          this.formData.actualAmount = undefined
        }
      } else if (this.formData.includeTax == 0) { // 不含税
        if (!this.isBlank(this.formData.signAmount) && !this.isBlank(this.formData.taxRate)) {
          this.formData.actualAmount = this.formData.signAmount * (1 + this.formData.taxRate / 100)
        } else {
          this.formData.actualAmount = undefined
        }
      }
    },
    // 新增产品/明细行
    handleAddProductRow() {
      this.formData.products.push({
        productId: '',
        quantity: undefined,
        salesUnitPrice: undefined,
        amount: undefined,
        remark: ''
      })
    },
    // 新增产品/服务
    handleAddProduct() {
      this.showAddEditProductDialog = true
    },
    // 移除产品/明细
    handleRemoveProduct(index) {
      this.formData.products.splice(index, 1)
      this.calculateRowAmount()
    },
    // 点击保存
    handleSave(isSubmit = true) {
      for(let i = 0; i < this.formData.products.length; i++) {
        if (
          !this.formData.products[i].productId ||
          !this.formData.products[i].quantity ||
          (!this.formData.products[i].salesUnitPrice && this.formData.products[i].salesUnitPrice != 0)
        ) {
          return this.$message.error('请完善产品/服务信息')
        }
      }
      this.$refs.addEditContractForm.validate(valid => {
        if (!valid) return
        let fn = null
        if (this.operType == 'add') fn = contractAdd
        else if (this.operType == 'edit') fn = contractEdit
        else if (this.operType == 'update') fn = contractUpdate
        const data = this.getFormData()
        data.submit = isSubmit
        fn(data).then(res => {
          this.$message.success('操作成功')
          this.dialogVisible = false
          this.$emit('refresh')
        }).catch(err => {})
      })
    },
    handleAddItem() {
      this.isAddItem = !this.isAddItem
      this.formData.itemId = ''
      this.formData.itemName = ''
    },
    // 文件上传前
		handleBeforeUpload(file) {
			// let isPDF = (file.type === 'application/pdf')
			// if (!isPDF) {
			// 	this.$message.warning('仅支持pdf格式，请重新上传!')
			// }
			// return isPDF
      return true
		},
    // 文件上传成功
    handleSuccessFile(res, file, fileList) {
			if (res.code == 500) {
				return this.$message.error(res.msg)
			}
			this.attachmentFileList = fileList
    },
    // 文件上传失败
    handleErrorFile(err, file, fileList) {
      this.$message.error('文件上传失败')
    },
    // 移除文件
    handleRemoveFile(file, fileList) {
      this.attachmentFileList = fileList
		},
    // 预览文件
    handlePreviewFile(file, fileList) {
			if (file.response && file.response.data) {
				window.open(file.response.data.url, 'PDF', '')
			} else if (file.url) {
				window.open(file.url, 'PDF', '')
			}
		},
  },
}
</script>

<style lang="scss" scoped>
.addedit-contract-dialog {

  ::v-deep .el-dialog__body {
    max-height: 85vh;
    overflow-y: auto;
  }

  .append {
    position: absolute;
    right: 10px;
  }

  .el-divider {
    margin-top: 5px;
  }
}
</style>

<style lang="scss">
.project-select-popper {
  max-width: 800px;
}
</style>
